set(QNX TRUE)
set(CMAKE_SYSTEM_NAME QNX)

if(ARM_TARGET_ARCH_ABI STREQUAL "armv8")
  set(arch gcc_ntoaarch64le_cxx)
  set(ntoarch aarch64)
  set(QNX_PROCESSOR aarch64)
elseif(ARM_TARGET_ARCH_ABI STREQUAL "armv7")
  set(arch gcc_ntoarmv7le_cxx)
  set(ntoarch armv7)
  set(QNX_PROCESSOR armle-v7)
else()
  message(FATAL_ERROR "QNX only supports ARM_TARGET_ARCH_ABI=armv8 or armv7!")
endif()

set(QNX_HOST "$ENV{QNX_HOST}")
set(QNX_TARGET "$ENV{QNX_TARGET}")
if(NOT QNX_HOST)
  message(FATAL_ERROR "Environment variable QNX_HOST not set!")
endif()
if(NOT QNX_TARGET)
  message(FATAL_ERROR "Environment variable QNX_TARGET not set!")
endif()

set(CMAKE_C_COMPILER ${QNX_HOST}/usr/bin/qcc)
set(CMAKE_C_COMPILER_TARGET ${arch})
set(CMAKE_CXX_COMPILER ${QNX_HOST}/usr/bin/q++)
set(CMAKE_CXX_COMPILER_TARGET ${arch})
set(CMAKE_ASM_COMPILER qcc -V${arch})
set(CMAKE_ASM_DEFINE_FLAG "-Wa,--defsym,")
set(CMAKE_STRIP ${QNX_HOST}/usr/bin/nto${ntoarch}-strip CACHE PATH "QNX strip program" FORCE)

add_definitions(-DLITE_WITH_QNX)
add_definitions(-D_QNX_SOURCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -V${arch} -fPIC -D_QNX_SOURCE=1")
